home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 7
/
BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso
/
Files
/
DA
/
P
/
PCalculator.cpt
/
CalcDA sources
/
CalcDA_ASCII.c
< prev
next >
Wrap
Text File
|
1990-07-06
|
5KB
|
176 lines
/*
* CalcDA_ASCII.c for the Programmer's Calculator project
*
* Copyright 1990, Peter Ohler
*
* All Rights Reserved
*
* The Programmer's Calculator and the source code are shareware. That means
* they are not free. If you use either the source or the calculator then
* send $5 or $10 (whatever you feel its worth) to the address that follows.
* The source and calculator can be distributed for free. Prior to any sale
* of either the source code or the calculator my permission must be
* obtained. This includes sales by shareware distribution houses that sell
* shareware.
*
* Peter Ohler
*
* 3184 Rohrer Drive, Lafayette CA 94549
*
* (415) 284-7828
*
* ***************************************************************************
*
* I can never remember all the ASCII characters used on the MAC and can only
* remember a few of the hex values for the character set. The ASCII window
* displays the ASCII character in an array of the high and low bytes for
* each character.
*/
#include <DeviceMgr.h>
#include <WindowMgr.h>
#include <pascal.h>
#include "CalcDA.h"
/*
* ***************************************************************************
* #defines
*/
#define ASCII_WIDTH 318
#define ASCII_HIEGHT 270
#define ASCII_V_SPC 15
#define ASCII_H_SPC 18
#define ASCII_V_EDGE 36
#define ASCII_H_EDGE 30
/*
* ***************************************************************************
* prototypes
*/
extern void CenterDrawPStr(char *str, int left, int right, int bottom);
extern void MoveDrawPStr(char *str, int h, int v);
int DoAscii(void);
void UpdateAscii(void);
/*
* ***************************************************************************
* variables
*/
extern DCtlPtr deviceControlEntry; /* device control entry */
WindowPtr AsciiWindow = 0L;
/* The first 32 non-printing characters. */
char lowAscii[32][4] = { "\pNUL", "\pSOH", "\pSTX", "\pETX", "\pEOT", "\pENQ",
"\pACK", "\pBEL", "\pBS", "\pHT", "\pLF", "\pVT",
"\pFF", "\pCR", "\pSO", "\pSI", "\pDLE", "\pDC1",
"\pDC2", "\pDC3", "\pDC4", "\pNAK", "\pSYN", "\pETB",
"\pCAN", "\pEM", "\pSUB", "\pESC", "\pFS", "\pGS",
"\pRS", "\pUS"
};
/*
* ***************************************************************************
* functions
*/
int
DoAscii()
{
GrafPtr savePort;
Rect bounds;
Point pt;
GetPort(&savePort);
if (AsciiWindow) {
DisposeWindow(AsciiWindow);
AsciiWindow = 0L;
} else {
SetPort(CalcWindow);
SetPt(&pt, CalcWindow->portRect.right, CalcWindow->portRect.top);
LocalToGlobal(&pt);
pt.h += 6;
pt.v += 20;
SetRect(&bounds, pt.h, pt.v, pt.h + ASCII_WIDTH,
pt.v + ASCII_HIEGHT);
/*
* No close box. If one is allowed then closing the ASCII
* window will cause the DA to get a goodbye when it is
* closed. To avoid this behavior we use a button on the
* calculator to close the ASCII window.
*/
if (0L == (AsciiWindow = NewWindow(0L, &bounds, "\pASCII Chart",
TRUE, 18, -1L, FALSE, 0L)))
return -1;
/* IMPORTANT - set the windowkind to the dCtlRefNum */
((WindowPeek)AsciiWindow)->windowKind = deviceControlEntry->dCtlRefNum;
}
SetPort(savePort);
return 0;
}
void
UpdateAscii()
{
int h, v, i, ch;
char *c;
Rect bounds = { ASCII_V_EDGE - 12,
ASCII_H_EDGE - ASCII_H_SPC / 2 + 3,
ASCII_V_EDGE + 16 * ASCII_V_SPC - 12,
ASCII_H_EDGE + 16 * ASCII_H_SPC - ASCII_H_SPC / 2 + 3 };
/*
* We use our own patterns since the globals for quickdraw are not
* directly available in a DA. (without using a hardcoded address
* for them and working with offsets. I like to avoid that when
* possible.)
*/
Pattern myGray = { 170, 85, 170, 85, 170, 85, 170, 85 };
Pattern myBlack = { 255, 255, 255, 255, 255, 255, 255, 255 };
TextFont(courier);
TextSize(12);
TextFace(bold);
for (i = 0, c = "high byte"; *c; c++, i++) {
MoveTo(4, i * 12 + (bounds.bottom + bounds.top) / 2 - 54);
DrawChar(*c);
}
CenterDrawPStr("\plow byte ", bounds.left, bounds.right, 10);
PenPat(myGray);
for (i = 0; i < 16; i++) {
ch = i + ((i < 10) ? '0' : 'A' - 10);
MoveTo(ASCII_H_EDGE + i * ASCII_H_SPC, ASCII_V_EDGE - 14);
DrawChar(ch);
MoveTo(ASCII_H_EDGE - 14, ASCII_V_EDGE + i * ASCII_V_SPC);
DrawChar(ch);
}
for (i = 1; i < 16; i++) {
MoveTo(bounds.left + i * ASCII_H_SPC, bounds.top);
Line(0, bounds.bottom - bounds.top - 1);
MoveTo(bounds.left, bounds.top + i * ASCII_V_SPC);
Line(bounds.right - bounds.left - 1, 0);
}
PenPat(myBlack);
FrameRect(&bounds);
TextFace(0);
for (v = 0; v < 16; v++) {
for (h = 0; h < 16; h++) {
ch = v * 16 + h;
if (ch < 32) {
TextSize(9);
MoveDrawPStr(lowAscii[ch],
ASCII_H_EDGE + h * ASCII_H_SPC - 4,
ASCII_V_EDGE + v * ASCII_V_SPC - 1);
} else {
TextSize(12);
MoveTo(ASCII_H_EDGE + h * ASCII_H_SPC,
ASCII_V_EDGE + v * ASCII_V_SPC);
DrawChar(ch);
}
}
}
}